﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meraz.Core.Model;
using Meraz.Core.Cache;
using Meraz.Core.Data;

namespace Meraz.Core.Repositories
{
    public interface ITwitterUserRepository : IRepository<TwitterUser, long> { TwitterUser GetByUsername(string username); }
    public class TwitterUserRepository : EFRepositoryBase<TwitterUser, long>, ITwitterUserRepository
    {
        public TwitterUserRepository() { }

        public override TwitterUser GetById(long id)
        {
            TwitterUser obj = context.TwitterUsers
                .Where(where1 => where1.ID == id)
                .FirstOrDefault();
            return obj;
        }

        public TwitterUser GetByUsername(string username)
        {

            TwitterUser obj = context.TwitterUsers
                .Where(where1 => where1.Name == username)
                .FirstOrDefault();
            return obj;
        }

        public override void Add(TwitterUser entity)
        {
            this.context.AddToTwitterUsers(entity);
        }

        public override void Delete(TwitterUser entity)
        {
            this.context.TwitterUsers.DeleteObject(entity);
        }

        public override List<TwitterUser> All()
        {
            return this.context.TwitterUsers.ToList();
        }
    }
}
